package com.k.kpp.web.controller;

import com.k.kc.common.resp.RespPageDto;
import com.k.kpp.model.UserReq;
import com.k.kpp.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author k
 */
@Controller
public class UserController {
    private final static Logger LOGGER = LoggerFactory.getLogger(UserController.class);

    private UserService userServiceImpl;

    @RequestMapping("/user")
    public String userIndex(){
        LOGGER.debug("/user");
        return "user";
    }

    @RequestMapping("/user/list")
    @ResponseBody
    public List userList(@RequestBody UserReq userReq){
        LOGGER.debug("/user/list inParams:{}",userReq);
        return userServiceImpl.selectUser();
    }

    @RequestMapping("/user/listByPage")
    @ResponseBody
    public RespPageDto userListByPage(@RequestBody UserReq userReq){
        LOGGER.debug("/user/listByPage inParams:{}",userReq);
        userReq.startPage();
        Long count = userServiceImpl.selectCount(userReq);
        List list = userServiceImpl.selectListByPage(userReq);

        RespPageDto resp = new RespPageDto();
        resp.getSuccessForPager(userReq,count,list);
        return resp;
    }
    @RequestMapping("/user/deleteArr")
    @ResponseBody
    public String deleteArr(){
        Integer[] idArr = new Integer[]{8,9,10};
        int r = userServiceImpl.deleteArr(idArr);
        System.out.println("result:"+r);
        return String.valueOf(r);
    }
    @RequestMapping("/user/deleteList")
    @ResponseBody
    public String deleteList(){
        List<Integer> idList = new ArrayList<>();
        idList.add(5);
        idList.add(6);
        idList.add(7);
        int r = userServiceImpl.deleteList(idList);
        System.out.println("result:"+r);
        return String.valueOf(r);
    }

    @Autowired
    public void setUserServiceImpl(UserService userServiceImpl){
        this.userServiceImpl = userServiceImpl;
    }
}
